//
//  KYSportingVC.m
//  kyysprot
//
//  Created by HongYi on 2017/7/1.
//  Copyright © 2017年 kcvly. All rights reserved.
//

#import "KYSportingVC.h"

#import <MAMapKit/MAMapKit.h>
#import "KYSportMapVC.h"
#import "KYTransitionController.h"

@interface KYSportingVC ()
@property (nonatomic, weak) KYSportMapVC *sportMapVC;

@end

@implementation KYSportingVC {
    KYTransitionController *_transitionController;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        // 如不设置为自定义，dismiss时会有黑块
        self.modalPresentationStyle = UIModalPresentationCustom;
        _transitionController = [[KYTransitionController alloc] init];
        self.transitioningDelegate = _transitionController;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.sportMapVC.sportTracking = [[KYSportTracking alloc] initWithType:self.sportType];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)changeSportState:(UIButton *)sender {
    KYSportState sportState = sender.tag;
    self.sportMapVC.sportTracking.sportState = sportState;
}

- (KYSportMapVC *)sportMapVC {
    if (nil == _sportMapVC) {
        for (UIViewController *vc in self.childViewControllers) {
            if (![vc isKindOfClass:[KYSportMapVC class]]) {
                continue;
            }
            
            _sportMapVC = (KYSportMapVC *)vc;
            break;
        }
    }
    return _sportMapVC;
}

@end
